import axios from 'axios';

const apiClient = axios.create({
  baseURL: process.env.VUE_APP_API_URL || 'http://localhost:3000',
  headers: {
    'Content-Type': 'application/json',
  },
});

// 添加请求拦截器用于模拟API响应
apiClient.interceptors.response.use(
  response => response,
  error => {
    // 如果是真实API未连接，返回模拟成功响应
    if (!error.response) {
      console.log('使用模拟数据');
      return Promise.resolve({
        data: {
          success: true,
          message: '预约成功',
          orderId: Date.now()
        }
      });
    }
    return Promise.reject(error);
  }
);

export default {
  // 家政服务接口
  placeOrder(orderData) {
    return apiClient.post('/api/place-order', orderData);
  },
  getServiceReviews(serviceId) {
    return apiClient.get(`/api/service-reviews/${serviceId}`);
  },
  submitServiceReview(reviewData) {
    return apiClient.post('/api/submit-service-review', reviewData);
  },
  // 健康管理接口
  getHealthData() {
    return apiClient.get('/api/health-data');
  },
  // 社交与活动接口
  joinActivity(activityId) {
    return apiClient.post('/api/join-activity', { activityId });
  },
  // 时间银行接口
  getTimeBankPoints() {
    return apiClient.get('/api/time-bank-points');
  },
  exchangePoints(exchangeData) {
    return apiClient.post('/api/exchange-points', exchangeData);
  },
};